package com.ly.base.chapter03;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;

/**
 * FlatMap:降维
 */
public class ACFlatMapDemo {

    record Fruit(String cname, String name, String category, String color) { }
    public static void main(String[] args) {
        Stream.of(
                List.of(
                        new Fruit("草莓", "Strawberry", "浆果", "红色"),
                        new Fruit("桑葚", "Mulberry", "浆果", "紫色"),
                        new Fruit("杨梅", "Waxberry", "浆果", "红色"),
                        new Fruit("蓝莓", "Blueberry", "浆果", "蓝色")
                ),
                List.of(
                        new Fruit("核桃", "Walnut", "坚果", "棕色"),
                        new Fruit("草莓", "Peanut", "坚果", "棕色")
                )
        )
//                .flatMap(list -> list.stream())
                .flatMap(Collection::stream)
                .forEach(System.out::println);

        System.out.println("===============================================================");
        Integer[][] array20 = {
                {1,2,3,},
                {4,5,6,},
                {7,8,9},
        };
        Arrays.stream(array20)
                .flatMap(array -> Arrays.stream(array))
                .forEach(System.out::println);

    }
}
